<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>验证码换帮卡</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<script type="text/javascript">
    $(function () {
        $("#getSmCodeBtn").click(function () {
            var cstId = $("#cstId").val();
            var bankId = $("#bankId").val();
            var _url = "<%=path%>/institution/cstCzbank/getChangeBankCardSMSCode.do?cstId=" + cstId + "&bankId=" + bankId;
            $.ajax({
                type: 'post',
                dataType: 'json',
                url: _url,
                success: function (msg) {
                    if (msg.success == 1) {
                        UIUtils.alertSuccess(msg.info);
                    } else {
                        UIUtils.alertWarning(msg.info);
                    }
                }
            });
        });
        // 换卡
        $("#changeCardBtn").click(function () {
            var valiresult = validateRequired();
            if(valiresult){
                var cstId = $("#cstId").val();
                var bankId = $("#bankId").val();
                var smCode = $("#smCode").val();
                var _url = "<%=path%>/institution/cstCzbank/changeCardBySMSCode.do?cstId=" + cstId + "&bankId=" + bankId + "&smCode=" + smCode;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    url: _url,
                    success: function (msg) {
                        if (msg.success == 1) {
                            UIUtils.alertSuccess(msg.info);
                            $("#changeCardBtn").hide();
                            $("#getSmCodeBtn").hide();
                            setTimeout(function(){
                                parent.$.ligerDialog.close(); //关闭弹出窗
                                parent.$(".l-dialog,.l-window-mask").remove();
                             },2500)
                        } else {
                             UIUtils.alertWarning(msg.info);
                        }
                    }
                });
            }
        });

    });
    //初始化Form
    function initForm() {
        $("#getSmCodeForm").ligerForm({
            validate: true
        });
    }
    //验证必填数据
    function validateRequired() {
        var smCode = $("#smCode").val();
        if (StringUtils.isEmpty(smCode)) {
                top.$.ligerDialog.SQalert({content: "验证码不能为空", SQ_type: "error"});
                return false;
        }
        var length = smCode.length;
        if(length>8){
            top.$.ligerDialog.SQalert({content: "请输入有效验证码", SQ_type: "error"});
            return false;
        }
        return true ;
    }

</script>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="getSmCodeForm">
            <div class="fieldset1 clearFix" style="">
                <div class="fieldBox">
                    <div class="label">验证码</div>
                    <div class="field">
                        <input name="smCode" id="smCode" type="text" validate="{required:true,number:true}" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="clearFix"></div>
                    <div class="btnsBox">
                        <span id="getSmCodeBtn" class="sq-button sq-button-round">获取验证码</span>
                        <span id="changeCardBtn" class="sq-button sq-button-round">换绑卡</span>
                    </div>
                </div>
                <!-- hide data -->
                <div class="fieldBox col_100" style="display:none;">
                    <div class="field">
                        <input name=cstId id="cstId" type="text" class="ui-textbox" value="${cstId}">
                        <input name=cstId id="bankId" type="text" class="ui-textbox" value="${bankId}">
                    </div>
                </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>
</body>
</html>